<template>
  <div>
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState">
        <a-form-item name="dateRange" label="结算日期" class="w-80">
          <a-range-picker v-model:value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
        </a-form-item>
        <a-form-item name="yllb" label="医疗类别" class="w-72 ml-4">
          <SelectItem v-model:value="formState.yllb" type="med_type" placeholder="请选择" />
        </a-form-item>
        <a-form-item name="tcq" label="社会保险经办机构" class="w-80 ml-4" :label-col="{ style: { width: '130px' } }">
          <SelectItem v-model:value="formState.tcq" type="DT00310" placeholder="请选择" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2">
      <div class="flex justify-end mb-2">
        <BaseExport type="医保" name="费用结算申请表" code="001220" :search-params="formState"> 导出 </BaseExport>
        <a-button type="primary" class="ml-2" ghost @click="onPrint"><BaseIcon name="PrinterOutlined" />打印</a-button>
      </div>
      <BaseTable fill :data-source="tableData" :loading="loading" :scroll="{ x: 1800 }" column-code="001220" />
    </a-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { message } from 'ant-design-vue'
import dayjs from 'dayjs'
import SearchContainer from '@/components/SearchContainer'

const formState = ref({
  dateRange: [dayjs().subtract(1, 'month').format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')], // 结算日期 // 结算日期
  yllb: '', // 医疗类别
  tcq: '' // 社会保险经办机构
})
const formRef = ref(null)
const { loading, tableData, getData } = useTable({
  url: '/outp/oupCharge/getWorkersSettlement',
  immediate: true,
  pagination: false,
  params: formState
})

const onPrint = async () => {
  const { code, msg, data } = await post('/outp/outPrint/printWorkersSettlement', {
    ...formState.value,
    stdate: formState.value.dateRange[0],
    eddate: formState.value.dateRange[1],
    type: '1'
  })
  if (code !== 0) return message.error(msg || '打印失败')
  window.openExe?.rpt(data) //调用winform打印
}
</script>
